export interface Type<T> {
    value: T
}

export function Create<T>(factory: () => T): Type<T> {
    return new LazyImpl(factory);
}

class LazyImpl<T> {
    constructor(factory: () => T) {
        this.factory = factory;
    }

    private valueCreated = false;
    private _value: T;
    public get value(): T {
        if (!this.valueCreated) {
            this._value = this.factory();
        }

        return this._value;
    }

    private readonly factory: () => T;
}
